package com.business.dynamic.service.impl;


import java.util.List;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.business.common.utils.StrKit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.business.common.dto.R;

import com.business.dynamic.entity.DynamicFilter;
import com.business.dynamic.mapper.DynamicFilterMapper;
import com.business.dynamic.service.DynamicFilterService;



/**
 * 动态过滤条件表:业务接口实现类
 * @author chenjiehong
 * @date 2019-11-29 15:15:38
 * @since 1.0
 */
@Service
public class DynamicFilterServiceImpl implements DynamicFilterService {
    
    @Autowired
    private DynamicFilterMapper dynamicFilterMapper;

    @Override
    public List<DynamicFilter> queryList(Integer type,String parentCategoryCode,String subCategoryCode){
        Wrapper<DynamicFilter> wrapper = new EntityWrapper<>();
        wrapper.eq("type",type);
        wrapper.eq("state",1);
        if(StrKit.isNotEmpty(subCategoryCode)){
            wrapper.eq("sub_category_code",subCategoryCode);
        }else{
            wrapper.eq("parent_category_code",parentCategoryCode);
        }
        List<DynamicFilter> result = dynamicFilterMapper.selectList(wrapper);
        //如果按子行业查询没有则查夫行业
        if((result == null || result.size() == 0) && StrKit.isNotEmpty(subCategoryCode)){
            Wrapper<DynamicFilter> newWrapper = new EntityWrapper<>();
            wrapper.eq("type",type);
            newWrapper.eq("parent_category_code",parentCategoryCode);
            result = dynamicFilterMapper.selectList(newWrapper);
        }
        return result;
    }
    
}